<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Adds a collection of SolrInputDocument instances to the index</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="solrclient.adddocument.html">« SolrClient::addDocument</a></li>
      <li style="float: right;"><a href="solrclient.commit.html">SolrClient::commit »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.solrclient.html">SolrClient</a></li>
    <li>Adds a collection of SolrInputDocument instances to the index</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="solrclient.adddocuments" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SolrClient::addDocuments</h1>
  <p class="verinfo">(PECL solr &gt;= 0.9.2)</p><p class="refpurpose"><span class="refname">SolrClient::addDocuments</span> &mdash; <span class="dc-title">Adds a collection of SolrInputDocument instances to the index</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-solrclient.adddocuments-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SolrClient::addDocuments</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$docs</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$overwrite</code><span class="initializer"> = <strong><code>true</code></strong></span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$commitWithin</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
   Adds a collection of documents to the index.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-solrclient.adddocuments-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">docs</code></dt>

     <dd>

      <p class="para">
       An array containing the collection of SolrInputDocument instances. This array must be an actual variable.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">overwrite</code></dt>

     <dd>

      <p class="para">
       Whether to overwrite existing documents or not. If <strong><code>false</code></strong> there will be duplicates (several documents with the same ID).
        
      </p>
        <div class="warning"><strong class="warning">警告</strong>
            <p class="para">
              PECL Solr &lt; 2.0 $allowDups was used instead of $overwrite, which does the same functionality with exact opposite bool flag.
            </p>
            <p class="para">
              $allowDups = false is the same as $overwrite = true
            </p>
        </div>
     </dd>

    
    
     <dt>
<code class="parameter">commitWithin</code></dt>

     <dd>

      <p class="para">
        Number of milliseconds within which to auto commit this document. Available since Solr 1.4 . Default (0) means disabled.
      </p>
      <p class="para">
        When this value specified, it leaves the control of when to do the commit
        to Solr itself, optimizing number of commits to a minimum while still
        fulfilling
        the update latency requirements, and Solr will automatically do a commit
        when the oldest add in the buffer is due.
       </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-solrclient.adddocuments-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    Returns a <span class="type"><a href="class.solrupdateresponse.html" class="type SolrUpdateResponse">SolrUpdateResponse</a></span> object or throws an exception on failure.
  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-solrclient.adddocuments-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws <span class="classname"><a href="class.solrclientexception.html" class="classname">SolrClientException</a></span> if the client had failed, or there was a connection issue.
  </p>
  <p class="para">
   Throws <span class="classname"><a href="class.solrserverexception.html" class="classname">SolrServerException</a></span> if the Solr Server had failed to process the request.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-solrclient.adddocuments-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4637">
    <p><strong>示例 #1 <span class="methodname"><strong>SolrClient::addDocuments()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$doc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrInputDocument</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">334455</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Software'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Lucene'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$doc2&nbsp;</span><span style="color: #007700">=&nbsp;clone&nbsp;</span><span style="color: #0000BB">$doc</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$doc2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">deleteField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$doc2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">334456</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$docs&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">$doc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$doc2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$updateResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addDocuments</span><span style="color: #007700">(</span><span style="color: #0000BB">$docs</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;no&nbsp;changes&nbsp;will&nbsp;be&nbsp;written&nbsp;to&nbsp;disk&nbsp;unless&nbsp;$commitWithin&nbsp;is&nbsp;passed&nbsp;or&nbsp;SolrClient::commit&nbsp;is&nbsp;called<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$updateResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 2
        )

)

</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-solrclient.adddocuments-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="solrclient.adddocument.html" class="methodname" rel="rdfs-seeAlso">SolrClient::addDocument()</a> - Adds a document to the index</span></li>
    <li class="member"><span class="methodname"><a href="solrclient.commit.html" class="methodname" rel="rdfs-seeAlso">SolrClient::commit()</a> - Finalizes all add/deletes made to the index</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>